<template>
  <div id="app">
    <button @click="toggle">显示和隐藏切换</button>
    <transition>
      <div class="box" v-if="flag">盒子的内容</div>
    </transition>
  </div>
</template>

<script>
export default {
  name: "App",
  components: {},
  data() {
    return {
      flag: true,
    };
  },
  methods: {
    toggle() {
      this.flag = !this.flag;
    },
  },
  mounted() {},
};
</script>

<style>
.box {
  width: 200px;
  height: 100px;
  background-color: purple;
}
/* 离开和进来的整个期间 */
.v-enter-active,
.v-leave-active {
  transition: all 3s;
}
/* 刚开始进入 */
.v-enter {
  color: yellow;
}
/* 完全进入 */
.v-enter-to {
  background-color: blue;
}
/* 刚要离开元素的样式设置-一般不设置到此样式中 */
/* 刚离开 */
.v-leave {
  opacity: 1;
}
/* 完全离开 */
.v-leave-to {
  opacity: 0;
  transform: translateX(200px);
}
</style>
